#!/usr/bin/env python3

#   1.输入两个数，求两个数的最大公约数
def maxCommonDivisor(n1, n2):
    for x in range(1, min(n1, n2) + 1):
        if (n1 % x == 0) and (n2 % x == 0):
             i = x
    print(i)
#---------------------------------------------------------------------------

def maxCommonDivisor(n1, n2):
    #  m = n1 if n1 < n2 else n2

    #  for x in range(n1 if n1 < n2 else n2, 1, -1):
    for x in range(min(n1, n2), 1, -1):
        if n1 % x == 0 and n2 % x == 0:
            return x

    return 1

#   2.输出1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6 ... + 1/99 - 1/100的结果（保留两位）
def divSum():
    i = 0
    for a in range(1, 101):
        if (a % 2) == 0:
            i -= (1/a)
        elif (a % 2) != 0:
            i += (1/a)
    print(round(i, 2))
#---------------------------------------------------------------------------

#   3.将八进制数转成10进制输出(不准用内置函数)
def oct2Dec(num):
    f = 1
    if num < 0:
        f = -1
        num *= -1

    s = 0
    i = 0

    while num > 0:
        if num % 10 > 7:
            return None
        s += num % 10 * 8 ** i
        i += 1
        num //= 10

    return s * f

#   4.已知1900年一月一号是星期一，问今年有多少个黑色星期五(每月13号是星期五)

#判断是否闰年
def isYear(year):
    return 1 if year % 400 == 0 or year % 4 == 0 and year % 100 != 0 else 0

#计算两个年之间天数
def countYearDays(sy, ey):
    days = 0
    while sy < ey:
        days += 365 + isYear(sy)
        sy += 1
    return days

#计算1月到指定月的天数
def countMonthDays(month, year):
    days = (month - 1) * 30 + month // 2

    if month == 9 or month == 11:
        days += 1

    if month > 2:
        days = days - 2 + isYear(year)

    return days

    # {
    #  1       0
    #  2       1
    #  3       1
    #  4       2
    #  5       2
    #  6       3
    #  7       3
    #  8       4
    #  9       5
    #  10      5
    #  11      6
    #  12      6

    #  1       0
    #  2       31
    #  3       31 + 28/29
    #  4       31 + 28/29 + 31
    #  5       31 + 28/29 + 31 + 30
    #  6       31 + 28/29 + 31 + 30 + 31
    #  7       31 + 28/29 + 31 + 30 + 31 + 30
    #  8       31 + 28/29 + 31 + 30 + 31 + 30 + 31
    #  9       31 + 28/29 + 31 + 30 + 31 + 30 + 31 + 31
    #  10      31 + 28/29 + 31 + 30 + 31 + 30 + 31 + 31 + 30
    #  11      31 + 28/29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31
    #  12      31 + 28/29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30
    #}

#黑色星期五
def blackFri(year):
    days = countYearDays(1900, year) + 13

    for m in range(1, 13):
        if (days + countMonthDays(m, year)) % 7 == 5:
            print(year, "年", m, "月 13 号是黑色星期五!")


#   5.张三从2000年1月1号开始过着三天打鱼两天晒网的日子，输入年月日，判断他在打鱼还是晒网
def fish(year, month, day):
    d = (countYearDays(2000, year) + countMonthDays(month, year) + day) % 5
    s = "晒网" if d == 4 or d == 0 else "打鱼"
    print(s)


#   6. 99乘法表
def table99():
    for a in range(0, 10):
        for b in range(1, a + 1):
            c = a * b
            print("%d * %d = %2d  " % (a, b, c), end='')
        print()




#控制菜单：
while True:
    print("1.最大公约数")
    print("2.输出1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6 ... + 1/99 - 1/100的结果(保留两位)")
    print("3.八进制转10进制")
    print("4.黑色星期五")
    print("5.判断张三打鱼还是晒网")
    print("6.九九乘法表")
    print("7.退出")
    sel = int(input("请输入[1 - 7]: "))
    print("-------------------------------------------")
    if sel == 1:
        print("两个数的最大公约数是: ",
                maxCommonDivisor(int(input("请输入第一个数: ")),
                                 int(input("请输入第二个数: "))))
    elif sel == 2:
        divSum()
    elif sel == 3:
        print("十进制: ", oct2Dec(int(input("请输入一个八进制数: "))))
    elif sel == 4:
        blackFri(2017)
    elif sel == 5:
        while True:
            i = int(input("请输入天数(输入0退出): "))
            if i == 0:
                break
            fish(2000, 1, i)
    elif sel == 6:
        table99()
    elif sel == 7:
        break
    print("-------------------------------------------")
